package com.ay.demo.akka.share;

import com.ay.demo.akka.msg.Message;
import com.ay.demo.akka.msg.ShareMessage;

import akka.actor.ActorRef;
import akka.actor.ActorSystem;

/**
 * 碰到问题参考README.md
 * @author Ackles
 */
public class ShareDemo {
	static ActorSystem actorSystem = ActorSystem.create("gameServer");
	static ShareContext context = new ShareContext(actorSystem);
	
	public static void main(String[] args) {
		testFunction();
		testFunction();
		testMultiMessage();
//		try {
//			TimeUnit.SECONDS.sleep(5);
//			System.exit(0);
//		} catch (Exception e) {
//			e.printStackTrace();
//		}
	}

	static void testMultiMessage() {
		for (int i = 0; i < 100; i ++) {
			testMessage(i);
		}
	}

	static void testMessage(int userId) {
		ActorRef proxy = context.getProxy();
		System.out.println(String.format("ShareDemo-testMessage, share_proxy:%s", proxy));
		proxy.tell(new ShareMessage(userId), ActorRef.noSender());
	}

	static void testFunction() {
		ActorRef actorRef = context.getProxy();
		System.out.println(String.format("ShareDemo, share_proxy:%s", actorRef));
		long userId = 10000;
		Message msg = new ShareMessage(userId);
		actorRef.tell(msg, ActorRef.noSender());
	}
}
